package com.h2o3.sample.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.h2o3.carmack.message.Message;
import com.h2o3.carmack.message.MessageHandler;
import com.h2o3.carmack.message.annotation.Handler;
import com.h2o3.carmack.message.annotation.HandlerMapping;
import com.h2o3.carmack.session.Session;
import com.h2o3.sample.service.ChatService;

/**
 * @author chensheng
 * @version $Id: DisconnectHandler.java, v 0.1 1/18/14 11:12 PM chensheng Exp $
 */
@Handler
@HandlerMapping("disconnect")
public class DisconnectHandler implements MessageHandler {
    private static final Logger logger = LoggerFactory.getLogger(DisconnectHandler.class);

    @Autowired
    private ChatService         chatService;

    @Override
    public void handle(Session session, Message message) {
        logger.info("正在断开链接，用户为" + session.get("userName"));

        chatService.quit(session);
    }

    public ChatService getChatService() {
        return chatService;
    }

    public void setChatService(ChatService chatService) {
        this.chatService = chatService;
    }
}
